package com.angus.modules.content.controller.work;

import com.angus.common.core.web.controller.BaseController;
import com.angus.common.core.web.domain.AjaxResult;
import com.angus.common.security.utils.SecurityUtils;
import com.angus.modules.content.dto.LearnRecordDto;
import com.angus.modules.content.service.ILearnRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liyanan
 * @date 2024/11/10 2:16 PM
 * @description
 */

@RestController
@RequestMapping("/front/learn")
public class LearnRecordController extends BaseController {

    @Autowired
    ILearnRecordService frontLearnRecordService;

    @PostMapping("/add")
    public AjaxResult addLearnRecord(@RequestBody LearnRecordDto dto) {
        Long userId = SecurityUtils.getUserId();
        frontLearnRecordService.addLearnRecord(userId, dto);
        return AjaxResult.success();
    }

    @GetMapping("/getLearnRecord/{courseCode}/{unitNum}")
    public AjaxResult getLearnRecord(@PathVariable("courseCode") String courseCode,
                                     @PathVariable("unitNum") Integer unitNum) {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(frontLearnRecordService.getLearnRecord(userId, courseCode,unitNum));
    }

    @PostMapping("/getLearnRecordRate")
    public AjaxResult getLearnRecord(@RequestBody LearnRecordDto dto) {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(frontLearnRecordService.queryLearnRecord(dto,userId));
    }
}
